package com.lock.chess.config;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@Data
public class ResponseApi<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;
    private String Token;
//    private T[] dataList;

    public static final String SUCCESS = "成功";
    public static final String FAILURE = "失败";


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public static String getSUCCESS() {
        return SUCCESS;
    }

    public static String getFAILURE() {
        return FAILURE;
    }

    public ResponseApi(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseApi(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public ResponseApi(int code, String message, T data, String Token) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.Token = Token;
    }

    public static <T> ResponseApi<T> success() {
        return new ResponseApi<>(HttpStatus.OK.value(), SUCCESS);
    }
//    public static <T> ResponseApi<T> success(String msg) {
//        return new ResponseApi<>(HttpStatus.OK.value(), msg);
//    }
    public static <T> ResponseApi<T>success(T data) {
        return new ResponseApi<>(HttpStatus.OK.value(), SUCCESS, data);
    }
    public static <T> ResponseApi<T>success(T data, String Token) {
        return new ResponseApi<>(HttpStatus.OK.value(), SUCCESS, data, Token);
    }
    public static <T> ResponseApi<T>fail(T data) {
        return new ResponseApi<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), FAILURE, data);
    }
    public static <T> ResponseApi<T>fail(String errmsg) {
        return new ResponseApi<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), errmsg,null);
    }
    public static <T> ResponseApi<T>fail(int code,String msg) {
        return new ResponseApi<>(code, msg, null);
    }

    public static <T> ResponseApi<T>fail(HttpStatus status,T data) {
        return new ResponseApi<>(status.value(), FAILURE, data);
    }

}
 